package com.example.demo.customer;


import com.example.demo.exception.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Objects;

@Service
public class CustomerService
{

    public final CustomerRepository  customerRepository;
    @Autowired
    public CustomerService(CustomerRepository customerRepository)
    {
        this.customerRepository = customerRepository;
    }

    List<Customer> getCustomers()
    {
        return customerRepository.findAll();
    }

    Customer getCustomer(Long id)
    {
      return customerRepository
              .findById(id)
              .orElseThrow(() -> new NotFoundException("customer"+ id + "无法找到"));
    }
}
